package com.itheima.demo4;

import java.io.File;
import java.io.IOException;

public class FileDemo6 {
    public static void main(String[] args) throws IOException {

        File file = new File("C:\\Users\\DZL\\IdeaProjects\\javaxuexi");
        long len = getLen(file);
        System.out.println(len);


    }

    public static long getLen(File stc){
        //1.定义变量进行累加
        long len = 0;
        File[] files = stc.listFiles();
        if (files != null){
            for (File file : files) {
                if (file.isFile()){
                    len = len + file.length();
                }else {
                    len = len + getLen(file);
                }
            }
        }
        return len;
    }

}
